import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split #继承划分训练集和测试机
from sklearn.neighbors import KNeighborsClassifier  #K近邻
import matplotlib.pyplot as plt
from collections import Counter     #用于统计分类正确的样本数
from sklearn.preprocessing import StandardScaler#导入用于归一化的包
from sklearn.model_selection import cross_val_score#k折
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import VotingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.neural_network import MLPClassifier


AF_input_frame=pd.read_excel('pre_treatment_data_feature_2.xlsx',sheet_name='AF_input')
nonAF_input_frame=pd.read_excel('pre_treatment_data_feature_2.xlsx',sheet_name='nonAF_input')
AF_label_frame=pd.read_excel('pre_treatment_data_feature_2.xlsx',sheet_name='AF_label')
nonAF_label_frame=pd.read_excel('pre_treatment_data_feature_2.xlsx',sheet_name='nonAF_label')

AF_input=AF_input_frame.to_numpy()
nonAF_input=nonAF_input_frame.to_numpy()
AF_label=AF_label_frame.to_numpy()
nonAF_label=nonAF_label_frame.to_numpy()


AF_label=AF_label.flatten()
nonAF_label=nonAF_label.flatten()


X=np.concatenate([AF_input,nonAF_input])
from sklearn.decomposition import PCA
#pca=PCA(n_components='mle',svd_solver='full')
raw_y=np.concatenate([AF_label[0:],nonAF_label[0:]])
acc_list=[]

for i in range(8,10):
    X1=X[:,[0,2,3,4,5,6,7,8,9]]
    pca=PCA(n_components=i,svd_solver='full')
    pca.fit(X1)
    raw_x=pca.transform(X1)


    #raw_x=X_PCA
    #raw_X=X

    ss=StandardScaler()
    raw_x=ss.fit_transform(raw_x)

    lf = MLPClassifier(hidden_layer_sizes=(50,), max_iter=100, alpha=1e-4,
                       solver='sgd', verbose=10, random_state=1,
                       learning_rate_init=.1)
    acc = cross_val_score(lf, raw_x, raw_y, cv=10, scoring="accuracy")
    mean_acc = np.array(acc).mean()
    print(mean_acc)
    acc_list.append(mean_acc)